<template>
  <div>
    <!-- 一条文章单元格 -->
    <van-cell>
      <!-- 标题区域的插槽 -->
      <template #title>
        <div class="title-box">
          <!-- 标题 -->
          <span>{{ ArticleObj.title }}</span>
          <!-- 单图 -->
          <!-- <van-image
            :src="ArticleObj.cover.images[0]"
            class="thumb"
            v-if="ArticleObj.cover.type === 1"
          >
          </van-image> -->

          <img
            class="thumb"
            v-if="ArticleObj.cover.type === 1"
            v-lazy="ArticleObj.cover.images[0]"
          />
        </div>
        <!-- 多图 -->
        <div class="thumb-box" v-if="ArticleObj.cover.type > 1">
          <!-- <van-image
            :src="item"
            v-for="(item, index) in ArticleObj.cover.images"
            :key="index"
            class="thumb"
          >
          </van-image> -->
          <lazy-component>
            <img
              v-for="(item, index) in ArticleObj.cover.images"
              v-lazy="item"
              :key="index"
              class="thumb"
            />
          </lazy-component>
        </div>
      </template>
      <!-- label 区域的插槽 -->
      <template #label>
        <div class="label-box">
          <div>
            <span>{{ ArticleObj.aut_name }}</span>
            <span>{{ ArticleObj.comm_count }}评论</span>
            <span>{{ formatDate(ArticleObj.pubdate) }}</span>
          </div>
          <!-- 反馈按钮 -->
          <van-icon
            name="cross"
            @click.stop="cross(ArticleObj.art_id)"
            v-if="flag"
          />
        </div>
      </template>
    </van-cell>
  </div>
</template>

<script>
import { timeAgo } from '@/utils/date.js'

export default {
  props: {
    // 文章列表对象
    ArticleObj: {
      type: Object,
    },
    // 控制文章列表上的x 按钮 展示与隐藏 为true 展示 为false隐藏
    flag: {
      type: Boolean,
      default: true,
    },
  },
  data() {
    return {}
  },
  methods: {
    // 点击文章列表上的x 按钮
    cross(id) {
      this.$emit('Cross', id)
    },
    // 格式化时间
    formatDate(str) {
      return timeAgo(str)
    },
  },
}
</script>

<style scoped lang="less">
/* 标题样式 */
.title-box {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
}

/* label描述样式 */
.label-box {
  display: flex;
  justify-content: space-between;
  align-items: center;
}

/* 文章信息span */
.label-box span {
  margin: 0 3px;
  &:first-child {
    margin-left: 0;
  }
}
/* 图片的样式, 矩形黄金比例：0.618 */
.thumb {
  width: 113px;
  height: 70px;
  background-color: #f8f8f8;
  object-fit: cover;
}

/* 三图, 图片容器 */
.thumb-box {
  display: flex;
  justify-content: space-between;
}
</style>
